package com.hyj.serve.manage;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.*;

@SpringBootApplication
@MapperScan({"com.hyj.serve.manage.dao"})
public class CentosManageApplication {

    public static void main(String[] args) {
        SpringApplication.run(CentosManageApplication.class, envArgs(args));
    }


    private static String[] envArgs(String[] args){
        Set<String> argSet = new HashSet<>();
        for (String arg : args) {
            if(arg.contains("=")){
                String[] split = arg.split("=");
                argSet.add(split[0]);
            }
        }

        Map<String, String> config = new HashMap<>();
        Map<String, String> systemEnv = System.getenv();
        for (Map.Entry<String, String> entry : systemEnv.entrySet()) {
            if(entry.getKey().startsWith("--") && !argSet.contains(entry.getKey())){
                config.put(entry.getKey(), entry.getValue().trim());
            }
        }

        int size = argSet.size()+config.size();
        List<String> list = new ArrayList<>(size);
        list.addAll(Arrays.asList(args));

        for (Map.Entry<String, String> entry : config.entrySet()) {
            list.add(entry.getKey()+"="+entry.getValue());
        }

        return list.toArray(new String[size]);
    }

}
